<template>
    <view class="ZCWallet">
		<nav-bars title="我的钱包" bgColor="transparent"></nav-bars>
		<view class="bgBox" :style="{'background-image':`url(${ImgUrl}/static/ZCWallet/bg.png)`}"></view>
		<view class="walletBox" :style="{'background-image':`url(${ImgUrl}/static/ZCWallet/topBg.png)`}">
			<view class="balanceBox">
				总资产（元）
				<view class="price">{{priceInfo.balance}}</view>
			</view>
			<view class="withdComData flex align-center justify-between">
				<view class="dataItem">
					可提现（元）
					<view class="price">{{priceInfo.cashout_amount}}</view>
				</view>
				<view class="dataItem">
					已提现（元）
					<view class="price">{{priceInfo.withdrawn_amount}}</view>
				</view>
				<view class="btn" @click="toWithdCom">
					提现
				</view>
			</view>
		</view>
		<view class="myBankCard flex align-center justify-between" @click="toMyBank">
			<view class="left flex align-center">
				<image :src="`${ImgUrl}/static/ZCWallet/icon.png`" mode=""></image>
				我的银行卡
			</view>
			<view class="right">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
    </view>
</template>
<script>
	import Https from '@/service/verification.js';
	import { GetZcWalletInfo } from '@/service/zcWallet.js'
    export default {
        components: {},
        data() {
            return {
				ImgUrl:this.$static,
				priceInfo:{}
			};
        },
        computed: {},
        watch: {},
        created() {},
        onLoad() {
			
		},
		onShow() {
			const that = this
			let token = uni.getStorageSync('token')
			if(!token){
				uni.showToast({
					title:'未登录，请先登录！',
					icon:'none'
				})
				setTimeout(()=>{
					uni.reLaunch({
						url:'/pages_login/pages/login/login/index'
					})
				},300)
			}else{
				that.getPriceInfo()
			}
		},
        methods: {
			// 进入提现页面
			toWithdCom(){
				// uni.navigateTo({
				// 	url:`/pagesOne/distri/withdCom/withdCom?level=${0}&allCanPrice=${this.priceInfo.cashout_amount}`
				// })
				this.getAccountInfo()
			},
			
			// 进入我的银行卡
			toMyBank(){
				this.getAccountInfo('bankCard')
			},
			
			// 获取钱包信息
			async getPriceInfo(){
				const that = this;
				let res = await GetZcWalletInfo()
				console.log(res,'余额信息')
				if(res.code == 1){
					that.priceInfo = res.data
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			},
			
			// 查询云商通账户信息
			getAccountInfo(type) {
				var that = this;
				let params = {};
				// let identityType = uni.getStorageSync('identityType'); //1企业,2个人
				// let isMaster = uni.getStorageSync('isMaster'); //1老板,0员工
				// console.log(identityType);
				Https.GetAccountMes(params).then(res => {
					if (res.code == 1) {
						// console.log(res.data);
						// member_type 会员类型(2企业会员,3个人会员)   is_realname 是否实名(0否,1是,2实名审核中)  is_phone	 是否绑定手机(0否,1是)
						// is_sign	是否签约(0否,1是)  signContract 签约参数 
						var data = res.data;
						if (data.is_realname == 0) {
							uni.showModal({
								title: '提示',
								content: '暂时还没实名验证,是否实名验证?',
								confirmText: '确定',
								success: function(res) {
									if (res.confirm) {
										// 会员类型(2企业会员,3个人会员)
										if (data.member_type == 2) {
											console.log(123);
											uni.navigateTo({
												url: '/pages_Verification/verification/select/certificate'
											});
											return;
										}
										if (data.member_type == 3) {
											console.log(456);
											uni.navigateTo({
												url: '/pages_Verification/verification/personal/personal'
											});
											return;
										}
									}
								}
							});
							return;
						}
						if (data.is_realname == 1) {
							if (data.is_phone == 0) {
								uni.showModal({
									title: '提示',
									content: '暂时还没绑定手机号,是否绑定?',
									confirmText: '确定',
									success: function(res) {
										if (res.confirm) {
											uni.navigateTo({
												url: '/pages_Verification/verification/bindPhone/BindPhone'
											});
										}
									}
								});
							} else if (data.is_sign == 0) {
								uni.showModal({
									title: '提示',
									content: '需要完善支付信息,是否继续?',
									confirmText: '确定',
									success: function(res) {
										if (res.confirm) {
											uni.navigateToMiniProgram({
												appId: 'wxc46c6d2eed27ca0a', //通商云平台账户小程序appId
												path: 'pages/merchantAddress/merchantAddress',
												extraData: {
													// 测试环境地址：url=https://test.allinpay.com/yungateway/member/signContract.html?
													// 生产环境地址：url=https://fintech.allinpay.com/yungateway/member/signContract.html?
													// targetUrl: 'https://test.allinpay.com/yungateway/member/signContract.html?' + data.signContract.data.param //商户拼接的请求报文
													targetUrl: data.signContract
												},
												envVersion: 'release', //develop 开发版  trial 体验版  release 正式版
												success(res) {
													// 打开成功
													console.log(res);
												}
											});
										}
									}
								});
								// let url = encodeURIComponent('https://test.allinpay.com/yungateway/member/signContract.html?' + data.signContract.data.param);
								// uni.navigateTo({
								// 	url: '/pagesOne/verification/webview?url=' + url
								// });
							} else if (data.is_phone == 1 && data.is_sign == 1) {
								if(type == 'bankCard'){ //进入银行卡
									if (data.member_type == 3) {
										// 个人
										uni.navigateTo({
											url: '/pages_Verification/verification/bankCard/bankCardList?memberType=3&level=0'
										});
									} else if (data.member_type == 2) {
										// 企业
										uni.navigateTo({
											url: '/pages_Verification/verification/bankCard/bankCardList?memberType=2&level=0'
										});
									}
								}else{ //进入提现
									uni.navigateTo({
										url:`/pagesOne/distri/withdCom/withdCom?level=${3}&allCanPrice=${this.priceInfo.cashout_amount}`
									})
								}
							}
							return;
						}
						if (data.is_realname == 2) {
							if (data.member_type == 3) {
								// 个人
								uni.navigateTo({
									url: '/pages_Verification/verification/status/status?isPersonal=true&status=0&isIndex=true'
								});
							} else if (data.member_type == 2) {
								// 企业
								uni.navigateTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=0&isIndex=true'
								});
							}
							return;
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
			},
			
		},
    };
</script>
<style lang="less" scoped>
.ZCWallet{
	position: relative;
	padding: 0 25rpx;
	.bgBox{
		width: 100%;
		height: 500rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: absolute;
		left: 0;
		top: 0;
	}
	.walletBox{
		width: 700rpx;
		height: 370rpx;
		margin-top: 20rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		color: #FFF0CD;
		padding: 68rpx 42rpx 52rpx 60rpx;
		position: relative;
		z-index: 20;
		.balanceBox{
			font: 400 28rpx/40rpx PingFang SC-Regular;
			.price{
				font: bold 58rpx/82rpx PingFang SC-Bold;
			}
		}
		
		.withdComData{
			margin-top: 40rpx;
			.dataItem{
				font: 400 18rpx/26rpx PingFang SC-Regular;
				.price{
					font: bold 32rpx/44rpx PingFang SC-Bold;
				}
			}
			.btn{
				width: 256rpx;
				height: 74rpx;
				border-radius: 38rpx;
				background-color: #D9B686;
				font: bold 30rpx/74rpx PingFang SC-Bold;
				color: #fff;
				text-align: center;
			}
		}
	}
	
	.myBankCard{
		width: 674rpx;
		margin: 20rpx auto;
		padding: 18rpx 26rpx;
		background-color: #fff;
		border-radius: 20rpx;
		font: 500 24rpx/34rpx PingFang SC-Medium;
		color: #333333;
		.left{
			image{
				width: 56rpx;
				height: 56rpx;
				flex-shrink: 0;
				margin-right: 18rpx;
			}
		}
	}
}

</style>